//
//  YGChuFangTableViewCell.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/4/30.
//

#import "YGChuFangTableViewCell.h"

@interface YGChuFangTableViewCell()
@property (nonatomic, strong) UIImageView  *coverImageView;
@property (nonatomic, strong) UILabel  *titleLabel;
@property (nonatomic, strong) UILabel   *desLabel;
@property (nonatomic, strong) UILabel  *priceLabel;
@property (nonatomic, strong) UIButton  *changeBtn;

@end
@implementation YGChuFangTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
        [self initMas];
    }
    return self;
}

- (void)initView{
    [self addSubview:self.coverImageView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.desLabel];
    [self addSubview:self.priceLabel];
    [self addSubview:self.changeBtn];
}

- (void)initMas{
    [self.coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(60);
        make.left.top.mas_equalTo(10);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.coverImageView.mas_top);
        make.height.mas_equalTo(15);
        make.left.mas_equalTo(self.coverImageView.mas_right).offset(15);
        make.right.mas_equalTo(self).offset(120);
    }];
    
    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.coverImageView.mas_centerY);
        make.height.mas_equalTo(15);
        make.left.mas_equalTo(self.coverImageView.mas_right).offset(15);
        make.right.mas_equalTo(self).offset(120);
    }];
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.coverImageView.mas_bottom);
        make.height.mas_equalTo(15);
        make.left.mas_equalTo(self.coverImageView.mas_right).offset(15);
        make.right.mas_equalTo(self).offset(120);
    }];
    
    [self.changeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(12);
        make.width.mas_equalTo(100);
        make.centerY.mas_equalTo(self.coverImageView.mas_centerY);
        make.right.mas_equalTo(self).offset(-10);
    }];
}

- (void)configureData:(YGgoodsModel *)model{
    [self.coverImageView sd_setImageWithURL:[NSURL URLWithString:model.thumbnail]];
    self.titleLabel.text = model.name;
    self.desLabel.text = @"";
    self.priceLabel.text = [NSString stringWithFormat:@"￥%d",model.price];
}

- (void)clickChange{
    
}
- (UIImageView *)coverImageView
{
    if(!_coverImageView){
        _coverImageView = [[UIImageView alloc] init];
    }
    return _coverImageView;
}

- (UILabel *)titleLabel
{
    if(!_titleLabel){
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:12];
        _titleLabel.textColor = UIColorFromRGB(0x333333);
    }
    return _titleLabel;
}

- (UILabel *)desLabel
{
    if(!_desLabel){
        _desLabel = [[UILabel alloc] init];
        _desLabel.font = [UIFont systemFontOfSize:12];
        _desLabel.textColor = UIColorFromRGB(0xE55667);
    }
    return _desLabel;
}

- (UILabel *)priceLabel
{
    if(!_priceLabel){
        _priceLabel = [[UILabel alloc] init];
        _priceLabel.font = [UIFont systemFontOfSize:12];
        _priceLabel.textColor = UIColorFromRGB(0xE55667);
    }
    return _priceLabel;
}

- (UIButton *)changeBtn
{
    if(!_changeBtn){
        _changeBtn = [[UIButton alloc] init];
        [_changeBtn setTitle:@"更换厂家/规格>>" forState:UIControlStateNormal];
        _changeBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_changeBtn setTitleColor:UIColorFromRGB(0x37C8D7) forState:UIControlStateNormal];
        [_changeBtn addTarget:self action:@selector(clickChange) forControlEvents:UIControlEventTouchUpInside];
    }
    return _changeBtn;
}

@end
